package com.example.j280_webproject.day036;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBC01_register {
    public boolean register(String username,String password) throws ClassNotFoundException, SQLException {
        boolean action = false;
        String driver = "com.mysql.jdbc.Driver";    //固定写法
        Class.forName(driver);                      //通过反射机制 把指定的类加载到当前类中

        //warning
        String url = "jdbc:mysql://localhost:3306/mygxa?useSSL=false&characterEncoding=UTF-8";
        String db_user = "root";
        String db_password = "root";
        Connection conn = DriverManager.getConnection(url, db_user, db_password);
        System.out.println("连接成功");

        //开发自己的数据库操作逻辑代码
        Statement statement = conn.createStatement();
        String sql = "insert into user(username, password, age) values ('"+username+"','"+password+"',18)";
        statement.execute(sql);//通过jdbc执行一条指定的指令

        conn.close();
        action = true;
        return action;
    }

}
